package com.ftg.learn.amqp.workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 布衣
 */
public class C2 {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("10.2.40.82");
        factory.setPort(5672);
        factory.setUsername("admin");
        factory.setPassword("admin");
        factory.setVirtualHost("/demo");
        Connection connection = factory.newConnection();

        Channel channel = connection.createChannel();

        String queueName = "working1";

        channel.basicConsume(queueName, true, (consumerTag, message) -> {
            System.out.println("接收到消息：" + new String(message.getBody()));
        }, consumerTag -> {
        });


    }
}
